package com.cc.mall.controller;

import java.util.Arrays;
import java.util.List;

import com.cc.common.utils.ResponseData;
import com.cc.mall.vo.CatalogVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.cc.mall.entity.ProductCategoryEntity;
import com.cc.mall.service.ProductCategoryService;
import com.cc.common.utils.R;



/**
 * 
 *
 * @author leifengyang
 * @email leifengyang@gmail.com
 * @date 2020-12-09 20:57:52
 */
@RestController
@RequestMapping("mall/productcategory")
@Api(tags="分类菜单")
public class ProductCategoryController {
    @Autowired
    private ProductCategoryService productCategoryService;

    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		ProductCategoryEntity productCategory = productCategoryService.getById(id);
        return R.ok().put("productCategory", productCategory);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody ProductCategoryEntity productCategory){
		productCategoryService.save(productCategory);
        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public R update(@RequestBody ProductCategoryEntity productCategory){
		productCategoryService.updateById(productCategory);
        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    public R delete(@RequestBody Long[] ids){
        System.out.println(ids);
		productCategoryService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

    @ApiOperation("进入商城时显示的商品分类")
    @GetMapping("/getCategory")
    public ResponseData<List<CatalogVo>> getCategory(){
        List<CatalogVo> catalogVoList = productCategoryService.getCategory();
        return ResponseData.success(catalogVoList);
    }

    @GetMapping("/getAllCategory")
    public R getAllCategory(){
        return R.ok().put("categoryList",productCategoryService.list(null));
    }

}
